﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Caching;
using System.Text;

namespace POC.Azure.Bag
{
    public  class CacheStore : IStore<object>
    {
        MemoryCache coolCache;
        public int HoldForMinutes { get; set; }
        public CacheStore(string key = null)
        {
            if (string.IsNullOrEmpty(key))
            {
                key = Guid.NewGuid().ToString();
            }
            coolCache = new MemoryCache(key);
            HoldForMinutes = 10;
        }
        public object Get(string key)
        {
            return coolCache.Get(key);
        }

        public void Put(string key, object item)
        {
            coolCache.Set(key, item, DateTime.Now.AddMinutes(HoldForMinutes));
        }

        public void Remove(string key)
        {
            coolCache.Remove(key);
        }

        public IEnumerable<KeyValuePair<string, object>> List()
        {
           return coolCache.ToList();
        }
    }
}
